package cvm;

import java.util.ArrayList;
import java.util.Iterator;

public class Pool {
	private String[] strings;
	private FunctionInfo[] methods;
	private double[] floats;
	private Object[] globalVariables;
	
	public Pool() {
		
	}
	
	public Pool(String[] strings, FunctionInfo[] methods, double[] floats, Object[] globalVariables) {
		super();
		this.strings = strings;
		this.methods = methods;
		this.floats = floats;
		this.globalVariables = globalVariables;
	}

	public Pool(String[] strings, FunctionInfo[] methods) {
		super();
		this.strings = strings;
		this.methods = methods;
		this.floats = null;
	}
	

	public Pool(String[] strings, double[] floats, FunctionInfo[] methods) {
		super();
		this.strings = strings;
		this.methods = methods;
		this.floats = floats;
	}
	
	public double getFloatLiteral(int index)
	{
		return floats[index-1];
	}
	
	
	
	public String[] getStrings() {
		return strings;
	}

	public void setStrings(String[] strings) {
		this.strings = strings;
	}

	public FunctionInfo[] getMethods() {
		return methods;
	}

	public void setMethods(FunctionInfo[] methods) {
		this.methods = methods;
	}

	public double[] getFloats() {
		return floats;
	}

	public void setFloats(double[] floats) {
		this.floats = floats;
	}

	public void setGlobalVariables(Object[] globalVariables) {
		this.globalVariables = globalVariables;
	}

	public String getString(int index)
	{
		return strings[index-1];
	}
	public FunctionInfo getMethod(int index)
	{
		return methods[index-1];
	}

	public int getPc(int index)
	{
		return methods[index-1].getPc();
	}
	/**
	 * @param index of the function
	 * @return the number of local variables
	 */
	public int getVariableCount(int index)
	{
		return methods[index-1].getVariableCount();
	}
	
	public int getParameterCOunt(int index)
	{
		return methods[index-1].getParamCount();
	}
	
	public Object getGlobalVariable(int index)
	{
		return globalVariables[index-1];
	}
	
	public Object[] getGlobalVariables() {
		return globalVariables;
	}
	
	public void setGlobalVariable(int index, Object o)
	{
		globalVariables[index-1] = o;
	}
	
	public void printPool()
	{
		System.out.println("Pool:");
		int j = 1;
		for(int i = 0; i<strings.length; i++)
			System.out.println("    #"+(i+(j++)+" "+strings[i]));
		for(int i = 0; i<floats.length; i++)
			System.out.println("    #"+(i+(j++)+" "+floats[i]));
		for(int i = 0; i<globalVariables.length; i++)
			System.out.println("    #"+(i+(j++)+" "+globalVariables[i]));
		for(int i = 0; i<methods.length; i++)
			System.out.println("    #"+(i+(j++)+" "+methods[i].toString()));
		System.out.println();
	}

}
